/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgQuestPhase
    {
        private readonly Dictionary<int, CfgQuestPhase> _dataMap;
        private readonly List<CfgQuestPhase> _dataList;


        public TbCfgQuestPhase(ByteBuf _buf)
        {
            //first read common data
            _TbCommonQuestPhase _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonQuestPhase(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgQuestPhase>(size * 3 / 2);
            _dataList = new List<CfgQuestPhase>(size);

            for (int i = 0; i < size; i++)
            {
                CfgQuestPhase _v;
                _v = CfgQuestPhase.DeserializeCfgQuestPhase(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgQuestPhase> DataMap => _dataMap;
        public IReadOnlyList<CfgQuestPhase> DataList => _dataList;

        public CfgQuestPhase Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgQuestPhase] config not found,id:" + key.ToString());

            return null;
        }

        public CfgQuestPhase GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "questphase";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgQuestPhase LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgQuestPhase(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgQuestPhase
    {
        private CfgQuestPhase(ByteBuf _buf, _TbCommonQuestPhase _commonData)
        {
            Id = _buf.ReadInt();
            QuestId = _buf.ReadInt();
            Phase = _buf.ReadInt();
            DescFormat = TableCenter.GetI18NText(_buf.ReadInt());
            Progress = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Reward = _commonData._field0[dataIndex]; }

            PostInit();
        }

        internal static CfgQuestPhase DeserializeCfgQuestPhase(ByteBuf _buf, _TbCommonQuestPhase _commonData)
        {
            return new CfgQuestPhase(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 任务id
        /// </summary>
        public int QuestId { get; private set; }
        /// <summary>
        /// 阶段_1开始
        /// </summary>
        public int Phase { get; private set; }
        /// <summary>
        /// 目标描述模板
        /// </summary>
        public string DescFormat { get; private set; }
        /// <summary>
        /// 进度
        /// </summary>
        public int Progress { get; private set; }
        /// <summary>
        /// 奖励
        /// </summary>
        public IReadOnlyList<int> Reward { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonQuestPhase
    {

        internal IReadOnlyList<IReadOnlyList<int>> _field0 { get; private set; }
        internal _TbCommonQuestPhase(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
